/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.insurance.cis.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author TruongLQ
 */
public final class HtmlReportUtils {
    
    private HtmlReportUtils() {
        throw new AssertionError();
    }
    
    public static void exportTitleVariances(BufferedWriter bw) {
        try {
            bw.write("<tr>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Campaign ID</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Campaign Name</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Product Name</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Estimated Budget</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Actual Budget</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Budget variance</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Estimated Sale</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Actual Sale</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Sale variance</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Start date</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>End date</b>");
            bw.write("</td>");
            bw.write("</tr>");
        } catch (IOException ex) {
            Logger.getLogger(HtmlReportUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public static void exportVariances(int row, BufferedWriter bw, DefaultTableModel dtm) {
        try {
            bw.write("<tr>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 0));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 1));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 2));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write(dtm.getValueAt(row, 6).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write(dtm.getValueAt(row, 7).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;background-color:red'>");
            bw.write(dtm.getValueAt(row, 8).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write(dtm.getValueAt(row, 9).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write(dtm.getValueAt(row, 10).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;background-color:red'>");
            bw.write(dtm.getValueAt(row, 11).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 12));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 13));
            bw.write("</td>");
            bw.write("</tr>");
        } catch (IOException ex) {
            Logger.getLogger(HtmlReportUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void exportTitleSalesTarget(BufferedWriter bw) {
        try {
            bw.write("<tr>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Campaign ID</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Campaign Name</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Product Name</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Channel description</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Estimate Sale</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Start date</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>End date</b>");
            bw.write("</td>");
            bw.write("</tr>");
        } catch (IOException ex) {
            Logger.getLogger(HtmlReportUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public static void exportSalesTarget(int row, BufferedWriter bw, DefaultTableModel dtm) {
        try {
            bw.write("<tr>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 0));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 1));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 2));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 3));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;background-color:red'>");
            bw.write(dtm.getValueAt(row, 9).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 12));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 13));
            bw.write("</td>");
            bw.write("</tr>");
        } catch (IOException ex) {
            Logger.getLogger(HtmlReportUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void exportTitleDefault(BufferedWriter bw) {
        try {
            bw.write("<tr>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Campaign ID</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Campaign Name</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Product Name</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Channel description</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Discount</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Gift</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Estimated Budget</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Actual Budget</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Budget variance</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Estimated Sale</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Actual Sale</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Sale variance</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Start date</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>End date</b>");
            bw.write("</td>");
            bw.write("</tr>");
        } catch (IOException ex) {
            Logger.getLogger(HtmlReportUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void exportDefault(int row, BufferedWriter bw, DefaultTableModel dtm) {
        try {
            bw.write("<tr>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 0));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 1));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 2));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 3));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write(dtm.getValueAt(row, 4).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 5));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write(dtm.getValueAt(row, 6).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write(dtm.getValueAt(row, 7).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;background-color:red'>");
            bw.write(dtm.getValueAt(row, 8).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write(dtm.getValueAt(row, 9).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write(dtm.getValueAt(row, 10).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;background-color:red'>");
            bw.write(dtm.getValueAt(row, 11).toString());
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 12));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 13));
            bw.write("</td>");
            bw.write("</tr>");
        } catch (IOException ex) {
            Logger.getLogger(HtmlReportUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void exportTitleDifferentCampaigns(BufferedWriter bw) {
        try {
            bw.write("<tr>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Campaign ID</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Campaign Name</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Product Name</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>Start date</b>");
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write("<b>End date</b>");
            bw.write("</td>");
            bw.write("</tr>");
        } catch (IOException ex) {
            Logger.getLogger(HtmlReportUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void exportDifferentCampaigns(int row, BufferedWriter bw, DefaultTableModel dtm) {
        try {
            bw.write("<tr>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 0));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 1));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 2));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 12));
            bw.write("</td>");
            bw.write("<td style='border:1px solid black;border-collapse:collapse;'>");
            bw.write((String) dtm.getValueAt(row, 13));
            bw.write("</td>");
            bw.write("</tr>");
        } catch (IOException ex) {
            Logger.getLogger(HtmlReportUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static String replaceImageLocation(File helpFile, 
            StringBuilder contents, String fileName) {
        String absolutePath = helpFile.getAbsolutePath();
        absolutePath = absolutePath.replaceAll(fileName, "");
        String replaceAll = contents.toString().replace("HELP_LOCATION", absolutePath);
        return replaceAll;
    }
}
